home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume6 / rpc2 / part10 < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  49.9 KB

  1. Subject:  v06i098:  Sun RPC Source (rpc2), Part10/11
  2. Newsgroups: mod.sources
  3. Approved: rs@mirror.UUCP
  4.  
  5. Submitted by: cca!SUN.COM!marks (Mark Stein)
  6. Mod.sources: Volume 6, Issue 98
  7. Archive-name: rpc2/Part10
  8.  
  9. [  All I have done is verify that this unpacks properly.  --r$  ]
  10.  
  11. Sun RPC source (part 10 of 11).  This software package contains code
  12. and documentation for Revision 3.0 of the Sun Remote Procedure Call
  13. library.  In addition, a beta version of the XDR/RPC protocol compiler
  14. is included.  Comments about this latest release may be mailed to
  15. sun!rpc or rpc@sun.com.
  16.  
  17. Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  18. unrestricted use provided that this legend is included on all tape
  19. media and as a part of the software program in whole or part.  Users
  20. may copy or modify Sun RPC without charge, but are not authorized to
  21. license or distribute it to anyone else except as part of a product or
  22. program developed by the user.
  23.  
  24. - - - - - - - - - C U T - H E R E - - - - - - - - - - - - - - - - - -
  25. #! /bin/sh
  26. # This is a shell archive, meaning:
  27. # 1. Remove everything above the #! /bin/sh line.
  28. # 2. Save the resulting text in a file.
  29. # 3. Execute the file with /bin/sh (not csh) to create:
  30. #    rpc/rpcgen/Makefile
  31. #    rpc/rpcgen/README
  32. #    rpc/rpcgen/rpc_cout.c
  33. #    rpc/rpcgen/rpc_hout.c
  34. #    rpc/rpcgen/rpc_main.c
  35. #    rpc/rpcgen/rpc_parse.c
  36. #    rpc/rpcgen/rpc_parse.h
  37. #    rpc/rpcgen/rpc_scan.c
  38. #    rpc/rpcgen/rpc_scan.h
  39. #    rpc/rpcgen/rpc_svcout.c
  40. # This archive created: Mon Jul 14 16:55:46 1986
  41. export PATH; PATH=/bin:/usr/bin:$PATH
  42. for d in rpc rpc/doc rpc/rpclib rpc/tools rpc/toys rpc/rpclib/profiled rpc/rpcgen rpc/rpcgen/test
  43. do
  44.     if test ! -d $d
  45.     then
  46.         echo "shar: Making directory $d"
  47.         mkdir $d
  48.         chmod 755 $d
  49.     fi
  50. done
  51. echo shar: "extracting 'rpc/rpcgen/Makefile'" '(956 characters)'
  52. if test -f 'rpc/rpcgen/Makefile'
  53. then
  54.     echo shar: "will not over-write existing file 'rpc/rpcgen/Makefile'"
  55. else
  56. sed 's/^X//' << \SHAR_EOF > 'rpc/rpcgen/Makefile'
  57. X#
  58. X#    @(#)Makefile 1.1 86/03/26 (C) 1986 SMI
  59. X#
  60. X# Makefile for rpc protocol compiler
  61. X# Copyright (C) 1986, Sun Microsystems, Inc.
  62. X#
  63. XOBJS= rpc_main.o rpc_hout.o rpc_cout.o rpc_parse.o rpc_scan.o rpc_util.o \
  64. X    rpc_svcout.o
  65. XSRCS= rpc_main.c rpc_hout.c rpc_cout.c rpc_parse.c rpc_scan.c rpc_util.c \
  66. X    rpc_svcout.c
  67. XHDRS= rpc_util.h rpc_parse.h rpc_scan.h
  68. X
  69. X# XDR_UPDATE used when rpc library used is pre-3.2
  70. XXDR_UPDATE = xdr_update.o
  71. XGOAL=rpcgen
  72. XCFLAGS = -O
  73. XDESTDIR=
  74. X
  75. Xall: $(GOAL) $(XDR_UPDATE)
  76. X
  77. X$(GOAL): $(OBJS) 
  78. X    cc $(CFLAGS) $(OBJS) -o $@
  79. X
  80. Xinstall: $(GOAL)
  81. X    install -s rpcgen $(DESTDIR)/usr/bin
  82. X    
  83. X
  84. X$(GOAL).lint: $(SRCS) $(HDRS)
  85. X    lint $(SRCS) > $@
  86. X
  87. Xclean:
  88. X    rm -f $(GOAL) $(OBJS) $(XDR_UPDATE)
  89. X
  90. Xrpc_util.c: rpc_util.h rpc_scan.h
  91. Xrpc_scan.c: rpc_util.h rpc_scan.h
  92. Xrpc_parse.c: rpc_util.h rpc_scan.h rpc_parse.h
  93. Xrpc_cout.c: rpc_util.h rpc_parse.h
  94. Xrpc_hout.c: rpc_util.h rpc_parse.h
  95. Xrpc_svcout.c: rpc_util.h rpc_parse.h
  96. Xrpc_main.c: rpc_util.h rpc_parse.h rpc_scan.h
  97. X
  98. SHAR_EOF
  99. if test 956 -ne "`wc -c < 'rpc/rpcgen/Makefile'`"
  100. then
  101.     echo shar: "error transmitting 'rpc/rpcgen/Makefile'" '(should have been 956 characters)'
  102. fi
  103. chmod 664 'rpc/rpcgen/Makefile'
  104. fi
  105. echo shar: "extracting 'rpc/rpcgen/README'" '(901 characters)'
  106. if test -f 'rpc/rpcgen/README'
  107. then
  108.     echo shar: "will not over-write existing file 'rpc/rpcgen/README'"
  109. else
  110. sed 's/^X//' << \SHAR_EOF > 'rpc/rpcgen/README'
  111. XThis directory contains the source for the RPC protocol compiler
  112. X`rpcgen.'   Rpcgen allows you to specify the protocol and data types
  113. Xused for an RPC service in a concise format, and will automatically
  114. Xgenerate the various stock components required to make a server for
  115. Xthat service.  See rpcgen.1 for usage information.
  116. X
  117. XThe `test' directory contains an example of how rpcgen might be used.
  118. X
  119. XThis software is from the Sun Microsystems 3.2Beta software release and
  120. Xis made available subject to the same conditions as the Remote
  121. XProcedure Call library.  Please send comments and bug reports to
  122. Xsun!rpc or rpc@sun.com.
  123. X
  124. X./xdr_update.c contains two xdr routines which have been added in
  125. X3.2 (and which rpcgen uses).  This file may either be loaded with the
  126. Xserver being built (as in the `test' directory), or may be added to the
  127. Xrpc library.  These routines will be part of the next rpc library
  128. Xrelease.
  129. SHAR_EOF
  130. if test 901 -ne "`wc -c < 'rpc/rpcgen/README'`"
  131. then
  132.     echo shar: "error transmitting 'rpc/rpcgen/README'" '(should have been 901 characters)'
  133. fi
  134. chmod 664 'rpc/rpcgen/README'
  135. fi
  136. echo shar: "extracting 'rpc/rpcgen/rpc_cout.c'" '(7980 characters)'
  137. if test -f 'rpc/rpcgen/rpc_cout.c'
  138. then
  139.     echo shar: "will not over-write existing file 'rpc/rpcgen/rpc_cout.c'"
  140. else
  141. sed 's/^X//' << \SHAR_EOF > 'rpc/rpcgen/rpc_cout.c'
  142. X#ifndef lint
  143. Xstatic char    sccsid[] = "@(#)rpc_cout.c 1.1 86/03/26 (C) 1986 SMI";
  144. X#endif
  145. X
  146. X/*
  147. X * rpc_cout.c, XDR routine outputter for the RPC protocol compiler
  148. X * Copyright (C) 1986, Sun Microsystems, Inc.
  149. X */
  150. X#include <stdio.h>
  151. X#include <strings.h>
  152. X#include "rpc_util.h"
  153. X#include "rpc_parse.h"
  154. X
  155. X#define SPECIALDEF 1    /* special if definition created by compiler */
  156. X#define NORMALDEF 0        /* normal if definition created by human */
  157. X
  158. X
  159. X/*
  160. X * Emit the C-routine for the given definition
  161. X */
  162. Xvoid
  163. Xemit(def)
  164. X    definition *def;
  165. X{
  166. X    do_emit(def,NORMALDEF);
  167. X}
  168. X
  169. X
  170. X
  171. Xstatic
  172. Xdo_emit(def,special)
  173. X    definition *def;
  174. X    int special;
  175. X{
  176. X
  177. X    if (def->def_kind == DEF_PROGRAM) {
  178. X        return;
  179. X    }
  180. X    if (isprinted(def->def_name)) {
  181. X        return;
  182. X    }
  183. X    print_undefineds(def);
  184. X    print_header(def,special);
  185. X    switch (def->def_kind) {
  186. X    case DEF_UNION:
  187. X        emit_union(def);
  188. X        break;
  189. X    case DEF_ARRAY:
  190. X        emit_array(def);
  191. X        break;
  192. X    case DEF_ENUM:
  193. X        emit_enum(def);
  194. X        break;
  195. X    case DEF_STRUCT:    
  196. X        emit_struct(def);
  197. X        break;    
  198. X    case DEF_TYPEDEF:
  199. X        emit_typedef(def);
  200. X        break;
  201. X    }
  202. X    print_trailer();
  203. X}
  204. X
  205. Xstatic
  206. Xfindtype(def,type)
  207. X    definition *def;
  208. X    char *type;
  209. X{
  210. X    if (def->def_kind == DEF_PROGRAM) {
  211. X        return(0);
  212. X    } else {
  213. X        return(streq(def->def_name,type));
  214. X    }
  215. X}
  216. X
  217. Xstatic
  218. Xundefined(type)
  219. X    char *type;
  220. X{
  221. X    definition *def;
  222. X
  223. X    def = (definition *) FINDVAL(defined,type,findtype);
  224. X    return(def == NULL);
  225. X}
  226. X
  227. Xstatic    
  228. Xisprinted(name)
  229. X    char *name;
  230. X{
  231. X    char *find;
  232. X
  233. X    find = (char *) FINDVAL(printed,name,streq);
  234. X    if (find) {
  235. X        return(1);
  236. X    }
  237. X    STOREVAL(&printed, name);
  238. X    return(0);
  239. X}
  240. X
  241. X
  242. X
  243. Xstatic char *
  244. Xformat_funcname(decp)
  245. X    declaration *decp;
  246. X{
  247. X    char buf[256];
  248. X    char *p;
  249. X
  250. X    switch (decp->rel) {
  251. X    case REL_POINTER:
  252. X        sprintf(buf,"%s_ptr",decp->type);
  253. X        break;
  254. X    case REL_VECTOR:
  255. X        if (streq(decp->type,"string") && decp->array_max == NULL) {
  256. X            sprintf(buf,"wrapstring");
  257. X        } else {
  258. X            sprintf(buf,"%s_%s",decp->type,decp->array_max);
  259. X        }
  260. X        break;
  261. X    case REL_ALIAS:
  262. X        sprintf(buf,"%s",decp->type);
  263. X        break;
  264. X    }
  265. X    p = alloc(strlen(buf) + 1);
  266. X    strcpy(p,buf);
  267. X    return(p);
  268. X}
  269. X
  270. X
  271. X
  272. X
  273. Xstatic 
  274. Xprint_undefineds(def)
  275. X    definition *def;
  276. X{
  277. X    case_list *cl;
  278. X    declaration *dflt;
  279. X
  280. X    if (def->def_kind != DEF_UNION) {
  281. X        return;
  282. X    }
  283. X    for (cl = def->def.un.cases; cl != NULL; cl = cl->next) {
  284. X        if (cl->case_decl.rel != REL_ALIAS) {
  285. X            emit_new(&cl->case_decl);
  286. X        }
  287. X    }
  288. X    dflt = def->def.un.default_decl;
  289. X    if (dflt) {
  290. X        if (dflt->rel != REL_ALIAS) {
  291. X            emit_new(dflt);
  292. X        }
  293. X    }
  294. X}
  295. X
  296. X
  297. Xstatic    
  298. Xemit_new(dec)
  299. X    declaration *dec;
  300. X{
  301. X    definition *def;
  302. X
  303. X    if (dec->rel == REL_VECTOR && streq(dec->type,"string") && 
  304. X            dec->array_max == NULL) {
  305. X        return;
  306. X    }
  307. X    def = ALLOC(definition);
  308. X    def->def_kind = DEF_TYPEDEF;
  309. X    def->def_name = format_funcname(dec);
  310. X    def->def.ty.old_prefix = dec->prefix;
  311. X    def->def.ty.old_type = dec->type;
  312. X    def->def.ty.rel = dec->rel;
  313. X    def->def.ty.array_max = dec->array_max;
  314. X    do_emit(def, SPECIALDEF);
  315. X}
  316. X
  317. Xstatic
  318. Xprint_header(def,special)
  319. X    definition *def;    
  320. X    int special;
  321. X{
  322. X    space();    
  323. X    if (special) {
  324. X        fprintf(fout,"static ");
  325. X    }
  326. X    fprintf(fout,"bool_t\n");
  327. X    fprintf(fout,"xdr_%s(xdrs,objp)\n",def->def_name);
  328. X    fprintf(fout,"\tXDR *xdrs;\n");
  329. X    if (special) {
  330. X        if (streq(def->def.ty.old_type,"string")) {
  331. X            fprintf(fout,"\tchar *");    
  332. X        } else if (streq(def->def.ty.old_type,"opaque")) {
  333. X            fprintf(fout,"\tchar *");
  334. X        } else if (streq(def->def.ty.old_type,"bool")) {
  335. X            fprintf(fout,"\tbool_t *");
  336. X        } else {
  337. X            fprintf(fout,"\t%s *",def->def.ty.old_type);
  338. X        }
  339. X    } else {
  340. X        fprintf(fout,"\t%s ",def->def_name);
  341. X    }
  342. X    if (def->def_kind != DEF_TYPEDEF  ||
  343. X            ! isvectordef(def->def.ty.old_type,def->def.ty.rel)) {
  344. X        fprintf(fout,"*");
  345. X    }
  346. X    fprintf(fout,"objp;\n");
  347. X    fprintf(fout,"{\n");
  348. X}
  349. X
  350. Xstatic
  351. Xtypedefed(def,type)
  352. X    definition *def;
  353. X    char *type;
  354. X{
  355. X    if (def->def_kind != DEF_TYPEDEF || def->def.ty.old_prefix != NULL) {
  356. X        return(0);
  357. X    } else {
  358. X        return (streq(def->def_name,type));
  359. X    }
  360. X}
  361. X
  362. Xstatic
  363. Xisvectordef(type,rel)
  364. X    char *type;
  365. X    relation rel;    
  366. X{
  367. X    definition *def;
  368. X
  369. X    for (;;) {
  370. X        switch (rel) {
  371. X        case REL_VECTOR:
  372. X            return(! streq(type,"string"));
  373. X        case REL_POINTER:
  374. X            return(0);
  375. X        case REL_ALIAS:    
  376. X            def = (definition *) FINDVAL(defined,type,typedefed);
  377. X            if (def == NULL) {
  378. X                return(0);
  379. X            }
  380. X            type = def->def.ty.old_type;
  381. X            rel = def->def.ty.rel;
  382. X        }
  383. X    }
  384. X}
  385. X    
  386. Xstatic
  387. Xprint_trailer()
  388. X{
  389. X    fprintf(fout,"\treturn(TRUE);\n");
  390. X    fprintf(fout,"}\n");
  391. X    space();
  392. X}
  393. X
  394. Xstatic
  395. Xprint_ifopen(name)
  396. X    char *name;
  397. X{
  398. X    fprintf(fout,"\tif (! xdr_%s(xdrs",name);
  399. X}
  400. X
  401. X
  402. Xstatic
  403. Xprint_ifarg(arg)
  404. X    char *arg;
  405. X{
  406. X    fprintf(fout,", %s",arg);
  407. X}
  408. X
  409. X
  410. Xstatic
  411. Xprint_ifsizeof(prefix,type)
  412. X    char *prefix;
  413. X    char *type;
  414. X{
  415. X    if (streq(type,"bool")) {
  416. X        fprintf(fout,", sizeof(bool_t), xdr_bool");
  417. X    } else {
  418. X        fprintf(fout,", sizeof(");
  419. X        if (undefined(type) && prefix) {
  420. X            fprintf(fout,"%s ",prefix);
  421. X        }
  422. X        fprintf(fout,"%s), xdr_%s",type,type);
  423. X    }
  424. X}
  425. X
  426. Xstatic
  427. Xprint_ifclose()
  428. X{
  429. X    fprintf(fout,")) {\n");
  430. X    fprintf(fout,"\t\treturn(FALSE);\n");
  431. X    fprintf(fout,"\t}\n");
  432. X}
  433. X
  434. Xstatic
  435. Xspace()
  436. X{
  437. X    fprintf(fout,"\n\n");
  438. X}
  439. X
  440. Xstatic
  441. Xprint_ifstat(prefix,type,rel,amax,name)
  442. X    char *prefix;
  443. X    char *type;
  444. X    relation rel;
  445. X    char *amax;
  446. X    char *name;
  447. X{
  448. X    char *alt = NULL;
  449. X
  450. X    switch (rel) {
  451. X    case REL_POINTER:
  452. X        print_ifopen("pointer");
  453. X        print_ifarg("(char *) ");
  454. X        fprintf(fout,name);
  455. X        print_ifsizeof(prefix,type);
  456. X        break;
  457. X    case REL_VECTOR:
  458. X        if (streq(type,"string")) {
  459. X            if (amax) {
  460. X                alt = "string";
  461. X            } else {
  462. X                alt = "wrapstring";    
  463. X            }
  464. X        } else if (streq(type,"opaque")) {
  465. X            alt = "opaque";
  466. X        }
  467. X        if (alt) {
  468. X            print_ifopen(alt);
  469. X            print_ifarg(name);
  470. X        } else {
  471. X            print_ifopen("vector");
  472. X            print_ifarg("(char *) ");
  473. X            fprintf(fout,name);
  474. X        }
  475. X        if (amax) {
  476. X            print_ifarg(amax);
  477. X        }
  478. X        if (! alt) {
  479. X            print_ifsizeof(prefix,type);
  480. X        }
  481. X        break;
  482. X    case REL_ALIAS:
  483. X        print_ifopen(type);
  484. X        print_ifarg(name);
  485. X        break;
  486. X    }
  487. X    print_ifclose();
  488. X}
  489. X
  490. X
  491. X/*ARGSUSED*/
  492. Xstatic
  493. Xemit_enum(def)
  494. X    definition *def;
  495. X{
  496. X    print_ifopen("enum");
  497. X    print_ifarg("(enum_t *) objp");
  498. X    print_ifclose();
  499. X}
  500. X
  501. X
  502. Xstatic
  503. Xemit_array(def)
  504. X    definition *def;
  505. X{
  506. X    array_def *ad = &def->def.ar;
  507. X    char *prefix = ad->array_prefix;
  508. X    char *type = ad->array_type;
  509. X    int bytes;
  510. X
  511. X    bytes = streq(type,"opaque");
  512. X    print_ifopen(bytes ? "bytes" : "array");
  513. X    print_ifarg("&objp->");
  514. X    fprintf(fout,ad->array_name);
  515. X    print_ifarg("(char *) &objp->");
  516. X    fprintf(fout,ad->len_name);
  517. X    print_ifarg(ad->array_max);
  518. X    if (! bytes) {
  519. X        print_ifsizeof(prefix,type);
  520. X    }
  521. X    print_ifclose();
  522. X}
  523. X
  524. X
  525. X
  526. Xstatic
  527. Xprint_funcname(decp)
  528. X    declaration *decp;
  529. X{
  530. X    char *buf;
  531. X
  532. X    buf = format_funcname(decp);
  533. X    fprintf(fout,buf);
  534. X    free(buf);
  535. X}
  536. X
  537. X
  538. X    
  539. Xstatic
  540. Xemit_union(def)
  541. X    definition *def;
  542. X{
  543. X    declaration *dflt;
  544. X    
  545. X
  546. X    print_tags(def);
  547. X    print_ifopen("union");
  548. X    print_ifarg("(enum_t *) &objp->");
  549. X    fprintf(fout,def->def.un.enum_decl.name);
  550. X    print_ifarg("(char *) &objp->");
  551. X    fprintf(fout,"%s",def->def_name);
  552. X    print_ifarg("choices");
  553. X    dflt = def->def.un.default_decl;
  554. X    if (dflt) {
  555. X        print_ifarg("xdr_");
  556. X        print_funcname(dflt);
  557. X    } else {
  558. X        print_ifarg("NULL");
  559. X    }
  560. X    print_ifclose();
  561. X}
  562. X
  563. X
  564. X
  565. Xstatic
  566. Xprint_tags(def)
  567. X    definition *def;
  568. X{
  569. X    case_list *cl;
  570. X
  571. X    fprintf(fout,"\tstatic struct xdr_discrim choices[] = {\n",def->def_name);
  572. X    for (cl = def->def.un.cases; cl != NULL; cl = cl->next) {
  573. X        fprintf(fout,"\t\t{ (int) %s, xdr_",cl->case_name);
  574. X        print_funcname(&cl->case_decl);
  575. X        fprintf(fout," },\n");
  576. X    }
  577. X    fprintf(fout,"\t\t{ __dontcare__, NULL }\n");
  578. X    fprintf(fout,"\t};\n");
  579. X    fprintf(fout,"\n");    
  580. X}
  581. X
  582. X
  583. Xstatic
  584. Xemit_struct(def)
  585. X    definition *def;
  586. X{
  587. X    decl_list *dl;
  588. X
  589. X    for (dl = def->def.st.decls; dl != NULL; dl = dl->next) {
  590. X        print_stat(&dl->decl);
  591. X    }
  592. X}
  593. X
  594. X
  595. X
  596. X        
  597. Xstatic
  598. Xemit_typedef(def)
  599. X    definition *def;
  600. X{
  601. X    char *prefix = def->def.ty.old_prefix;
  602. X    char *type = def->def.ty.old_type;
  603. X    char *amax = def->def.ty.array_max;
  604. X    relation rel = def->def.ty.rel;
  605. X
  606. X    print_ifstat(prefix,type,rel,amax,"objp");
  607. X}
  608. X
  609. X
  610. X
  611. X
  612. X
  613. Xstatic
  614. Xprint_stat(dec) 
  615. X    declaration *dec;
  616. X{
  617. X    char *prefix = dec->prefix;
  618. X    char *type = dec->type;
  619. X    char *amax = dec->array_max;
  620. X    relation rel = dec->rel;
  621. X    char name[256];
  622. X
  623. X    if (isvectordef(type,rel)) {
  624. X        sprintf(name,"objp->%s",dec->name);
  625. X    } else {
  626. X        sprintf(name,"&objp->%s",dec->name);
  627. X    }
  628. X    print_ifstat(prefix,type,rel,amax,name);
  629. X}
  630. SHAR_EOF
  631. if test 7980 -ne "`wc -c < 'rpc/rpcgen/rpc_cout.c'`"
  632. then
  633.     echo shar: "error transmitting 'rpc/rpcgen/rpc_cout.c'" '(should have been 7980 characters)'
  634. fi
  635. chmod 444 'rpc/rpcgen/rpc_cout.c'
  636. fi
  637. echo shar: "extracting 'rpc/rpcgen/rpc_hout.c'" '(5658 characters)'
  638. if test -f 'rpc/rpcgen/rpc_hout.c'
  639. then
  640.     echo shar: "will not over-write existing file 'rpc/rpcgen/rpc_hout.c'"
  641. else
  642. sed 's/^X//' << \SHAR_EOF > 'rpc/rpcgen/rpc_hout.c'
  643. X#ifndef lint 
  644. Xstatic char sccsid[] = "@(#)rpc_hout.c 1.1 86/03/26 (C) 1986 SMI";
  645. X#endif
  646. X/*
  647. X * rpc_hout.c, Header file outputter for the RPC protocol compiler
  648. X * Copyright (C) 1986, Sun Microsystems, Inc.
  649. X */
  650. X
  651. X#include <stdio.h>
  652. X#include <ctype.h>
  653. X#include "rpc_util.h"
  654. X#include "rpc_parse.h"
  655. X
  656. X
  657. X/*
  658. X * Print the C-version of an xdr definition
  659. X */
  660. Xvoid
  661. Xprint_datadef(def)
  662. X    definition *def;
  663. X{
  664. X    
  665. X    fprintf(fout,"\n");
  666. X    switch (def->def_kind) {
  667. X    case DEF_STRUCT:
  668. X        pstructdef(def);
  669. X        break;
  670. X    case DEF_UNION:
  671. X        puniondef(def);
  672. X        break;
  673. X    case DEF_ARRAY:
  674. X        parraydef(def);
  675. X        break;
  676. X    case DEF_ENUM:
  677. X        penumdef(def);
  678. X        break;
  679. X    case DEF_TYPEDEF:
  680. X        ptypedef(def);
  681. X        break;
  682. X    case DEF_PROGRAM:
  683. X        pprogramdef(def);
  684. X        break;
  685. X    }
  686. X    fprintf(fout,"\n");
  687. X}
  688. X
  689. X/*
  690. X * Declare all of the functions that were written
  691. X */
  692. Xvoid
  693. Xprint_funcdefs()
  694. X{
  695. X    list *l;
  696. X    definition *def;
  697. X
  698. X    for (l = defined; l != NULL; l = l->next) {
  699. X        def = (definition *) l->val;
  700. X        if (def->def_kind != DEF_PROGRAM) {
  701. X            fprintf(fout,"bool_t xdr_%s();\n",def->def_name);
  702. X        }
  703. X    }
  704. X}
  705. X
  706. Xstatic
  707. Xpstructdef(def)
  708. X    definition *def;
  709. X{
  710. X    decl_list *l;
  711. X    char *name = def->def_name;
  712. X
  713. X    fprintf(fout,"struct %s {\n",name);
  714. X    for (l = def->def.st.decls; l != NULL; l = l->next) {
  715. X        pdeclaration(name,&l->decl,1);
  716. X    }
  717. X    fprintf(fout,"};\n");
  718. X    fprintf(fout,"typedef struct %s %s;\n",name,name);
  719. X}
  720. X
  721. Xstatic
  722. Xpuniondef(def)
  723. X    definition *def;
  724. X{
  725. X    case_list *l;
  726. X    char *name = def->def_name;
  727. X    declaration *decl;
  728. X
  729. X    fprintf(fout,"struct %s {\n",name);
  730. X    decl = &def->def.un.enum_decl;
  731. X    fprintf(fout,"\t%s %s;\n",decl->type,decl->name);
  732. X    fprintf(fout,"\tunion {\n");
  733. X    for (l = def->def.un.cases; l != NULL; l = l->next) {
  734. X        pdeclaration(name,&l->case_decl,2);
  735. X    }
  736. X    decl = def->def.un.default_decl;
  737. X    if (decl && ! streq(decl->type,"void")) {
  738. X        pdeclaration(name,decl,2);
  739. X    }
  740. X    fprintf(fout,"\t} %s;\n",name);
  741. X    fprintf(fout,"};\n");
  742. X    fprintf(fout,"typedef struct %s %s;\n",name,name);
  743. X}
  744. X
  745. X
  746. X
  747. Xstatic
  748. Xpdefine(name,num)
  749. X    char *name;
  750. X    char *num;    
  751. X{
  752. X    
  753. X    fprintf(fout,"#define %s %s\n",name,num);
  754. X}
  755. X
  756. Xstatic
  757. Xdprinted(stop,start)
  758. X    proc_list *stop;
  759. X    version_list *start;
  760. X{
  761. X    version_list *vers;
  762. X    proc_list *proc;
  763. X
  764. X    for (vers = start; vers != NULL; vers = vers->next) {
  765. X        for (proc = vers->procs; proc != NULL; proc = proc->next) {
  766. X            if (proc == stop) {
  767. X                return(0);
  768. X            } else if (streq(proc->proc_name,stop->proc_name)) {
  769. X                return(1);
  770. X            }
  771. X        }
  772. X    }
  773. X    abort();    
  774. X    /* NOTREACHED */
  775. X}
  776. X    
  777. X    
  778. Xstatic
  779. Xpprogramdef(def)
  780. X    definition *def;
  781. X{
  782. X    version_list *vers;
  783. X    proc_list *proc;
  784. X
  785. X    pdefine(def->def_name,def->def.pr.prog_num);
  786. X    for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
  787. X        pdefine(vers->vers_name,vers->vers_num);
  788. X        for (proc = vers->procs; proc != NULL; proc = proc->next) {
  789. X            if (! dprinted(proc,def->def.pr.versions)) {
  790. X                pdefine(proc->proc_name,proc->proc_num);
  791. X            }
  792. X        }
  793. X    }
  794. X}
  795. X
  796. X
  797. Xstatic
  798. Xpenumdef(def)
  799. X    definition *def;
  800. X{
  801. X    char *name = def->def_name;
  802. X    enumval_list *l;
  803. X    char *last = NULL;
  804. X    int count = 0;
  805. X
  806. X    fprintf(fout,"enum %s {\n",name);
  807. X    for (l = def->def.en.vals; l != NULL; l = l->next) {
  808. X        fprintf(fout,"\t%s",l->name);
  809. X        if (l->assignment) {
  810. X            fprintf(fout," = %s",l->assignment);
  811. X            last = l->assignment;
  812. X            count = 1;
  813. X        } else {
  814. X            if (last == NULL) {
  815. X                fprintf(fout," = %d",count++);
  816. X            } else {
  817. X                fprintf(fout," = %s + %d",last,count++);
  818. X            }
  819. X        }    
  820. X        fprintf(fout,",\n");
  821. X    }
  822. X    fprintf(fout,"};\n");
  823. X    fprintf(fout,"typedef enum %s %s;\n",name,name);
  824. X}
  825. X
  826. Xstatic
  827. Xparraydef(def)
  828. X    definition *def;
  829. X{
  830. X    char *name = def->def_name;
  831. X    char *atype = def->def.ar.array_type;
  832. X    char *aname = def->def.ar.array_name;
  833. X
  834. X    fprintf(fout,"struct %s {\n",name);
  835. X    fprintf(fout,"\tu_int %s;\n",def->def.ar.len_name);
  836. X    if (streq(atype,"opaque")) {
  837. X        atype = "char";
  838. X    }
  839. X    fprintf(fout,"\t%s *%s;\n",atype,aname);
  840. X    fprintf(fout,"};\n");
  841. X    fprintf(fout,"typedef struct %s %s;\n",name,name);
  842. X}
  843. X    
  844. X
  845. Xstatic
  846. Xptypedef(def)
  847. X    definition *def;
  848. X{
  849. X    char *name = def->def_name;
  850. X    char *old = def->def.ty.old_type;
  851. X    char *prefix = def->def.ty.old_prefix;
  852. X    relation rel = def->def.ty.rel;
  853. X
  854. X    if (! streq(name,old)) {
  855. X        if (streq(old,"string")) {
  856. X            old = "char";
  857. X            rel = REL_POINTER;
  858. X        } else if (streq(old,"opaque")) {
  859. X            old = "char";
  860. X        } else if (streq(old,"bool")) {
  861. X            old = "bool_t";
  862. X        }    
  863. X        fprintf(fout,"typedef ");
  864. X        if (undefined2(old,name) && prefix) {
  865. X            fprintf(fout,"%s ",prefix);
  866. X        }
  867. X        fprintf(fout,"%s ",old);
  868. X        if (rel == REL_POINTER) {
  869. X            fprintf(fout,"*");
  870. X        }
  871. X        fprintf(fout,name);
  872. X        if (rel == REL_VECTOR) {
  873. X            fprintf(fout,"[%s]",def->def.ty.array_max);
  874. X        }
  875. X        fprintf(fout,";\n");
  876. X    }
  877. X}
  878. X
  879. Xstatic
  880. Xpdeclaration(name,dec,tab)
  881. X    char *name;
  882. X    declaration *dec;
  883. X    int tab;
  884. X{    
  885. X    if (streq(dec->type,"void")) {
  886. X        return;
  887. X    }
  888. X    while (tab--) {    
  889. X        fprintf(fout,"\t");
  890. X    }
  891. X    if (streq(dec->type,name) && ! dec->prefix) {
  892. X        fprintf(fout,"struct ");
  893. X    }
  894. X    if (streq(dec->type,"string")) {
  895. X        fprintf(fout,"char *%s",dec->name);
  896. X    } else {
  897. X        if (streq(dec->type,"bool")) {
  898. X            fprintf(fout,"bool_t ");
  899. X        } else if (streq(dec->type,"opaque")) {
  900. X            fprintf(fout,"char ");
  901. X        } else {
  902. X            if (dec->prefix) {
  903. X                if (streq(dec->prefix,"enum")) {
  904. X                    fprintf(fout,"enum ");
  905. X                } else {
  906. X                    fprintf(fout,"struct ");
  907. X                }
  908. X            }
  909. X            fprintf(fout,"%s ",dec->type);
  910. X        }
  911. X        if (dec->rel == REL_POINTER) {
  912. X            fprintf(fout,"*");
  913. X        }
  914. X        fprintf(fout,dec->name);
  915. X        if (dec->rel == REL_VECTOR) {
  916. X            fprintf(fout,"[%s]",dec->array_max);
  917. X        }
  918. X    }
  919. X    fprintf(fout,";\n");
  920. X}
  921. X
  922. X
  923. X
  924. Xstatic
  925. Xundefined2(type,stop)
  926. X    char *type;
  927. X    char *stop;
  928. X{
  929. X    list *l;
  930. X    definition *def;
  931. X
  932. X    for (l = defined; l != NULL; l = l->next) {
  933. X        def = (definition *) l->val;
  934. X        if (def->def_kind != DEF_PROGRAM) {
  935. X            if (streq(def->def_name,stop)) {
  936. X                return(1);
  937. X            } else if (streq(def->def_name,type)) {
  938. X                return(0);
  939. X            }
  940. X        }
  941. X    }
  942. X    return(1);
  943. X}
  944. SHAR_EOF
  945. if test 5658 -ne "`wc -c < 'rpc/rpcgen/rpc_hout.c'`"
  946. then
  947.     echo shar: "error transmitting 'rpc/rpcgen/rpc_hout.c'" '(should have been 5658 characters)'
  948. fi
  949. chmod 444 'rpc/rpcgen/rpc_hout.c'
  950. fi
  951. echo shar: "extracting 'rpc/rpcgen/rpc_main.c'" '(4370 characters)'
  952. if test -f 'rpc/rpcgen/rpc_main.c'
  953. then
  954.     echo shar: "will not over-write existing file 'rpc/rpcgen/rpc_main.c'"
  955. else
  956. sed 's/^X//' << \SHAR_EOF > 'rpc/rpcgen/rpc_main.c'
  957. X#ifndef lint 
  958. Xstatic char sccsid[] = "@(#)rpc_main.c 1.2 86/04/30 (C) 1986 SMI";
  959. X#endif
  960. X/*
  961. X * rpc_main.c, Top level of the RPC protocol compiler.
  962. X *
  963. X * Copyright (C) 1986, Sun Microsystems, Inc.
  964. X */
  965. X
  966. X#include <stdio.h>
  967. X#include <strings.h>
  968. X#include <sys/file.h>
  969. X#include "rpc_util.h"
  970. X#include "rpc_parse.h"
  971. X#include "rpc_scan.h"
  972. X
  973. Xstatic cflag;
  974. Xstatic hflag;
  975. Xstatic sflag;
  976. Xstatic char *cmdname;
  977. X
  978. Xmain(argc,argv)
  979. X    int argc;
  980. X    char *argv[];
  981. X{
  982. X
  983. X    cmdname = argv[0];
  984. X    if (! parseargs(argc,argv)) {
  985. X        fprintf(stderr,
  986. X            "usage: %s infile\n",cmdname);
  987. X        fprintf(stderr,
  988. X            "       %s [-c | -h] [-o outfile] [infile]\n",cmdname);
  989. X        fprintf(stderr,
  990. X            "       %s [-s udp|tcp]* [-o outfile] [infile]\n",
  991. X            cmdname);
  992. X        exit(1);
  993. X    }
  994. X    if (cflag) {
  995. X        open_input(infile);
  996. X        open_output(outfile,(char*)NULL);
  997. X        c_output();
  998. X    } else if (hflag) {
  999. X        open_input(infile);
  1000. X        open_output(outfile,(char*)NULL);
  1001. X        h_output();
  1002. X    } else if (sflag) {
  1003. X        open_input(infile);
  1004. X        open_output(outfile,(char*)NULL);
  1005. X        s_output(argc,argv);
  1006. X    } else {
  1007. X        open_input(infile);
  1008. X        open_output(infile,".c");
  1009. X        c_output();    
  1010. X        outfile2 = outfile;
  1011. X        reinitialize();
  1012. X        open_input(infile);    
  1013. X        open_output(infile,".h");
  1014. X        h_output();    
  1015. X    }
  1016. X}
  1017. X
  1018. Xchar *
  1019. Xextend(file,ext)
  1020. X    char *file;
  1021. X    char *ext;
  1022. X{
  1023. X    char *res;
  1024. X    char *p;
  1025. X
  1026. X    res = alloc(strlen(file) + strlen(ext) + 1);
  1027. X    if (res == NULL) {
  1028. X        abort();    
  1029. X    }
  1030. X    p = rindex(file,'.');
  1031. X    if (p == NULL) {
  1032. X        return(NULL);
  1033. X    }
  1034. X    strcpy(res,file);
  1035. X    strcpy(res + (p - file),ext);
  1036. X    return(res);
  1037. X}
  1038. X
  1039. X    
  1040. Xopen_output(file,ext)
  1041. X    char *file;
  1042. X    char *ext;
  1043. X{
  1044. X
  1045. X    if (file == NULL) {
  1046. X        fout = stdout;
  1047. X        return;
  1048. X    }
  1049. X    if (ext != NULL) {
  1050. X        if (! (outfile = extend(file, ext))) {
  1051. X            fprintf(stderr,"%s: %s has no extension\n",cmdname,file);
  1052. X            crash();    
  1053. X        }
  1054. X    } else {
  1055. X        outfile = file;
  1056. X    }
  1057. X    if (infile != NULL && streq(outfile,infile)) {
  1058. X        fprintf(stderr,"%s: output would overwrite %s\n",cmdname,infile);
  1059. X        outfile = NULL;
  1060. X        crash();
  1061. X    }
  1062. X    fout = fopen(outfile,"w");    
  1063. X    if (fout == NULL) {
  1064. X        fprintf(stderr,"%s: unable to open ",cmdname);
  1065. X        perror(outfile);
  1066. X        crash();    
  1067. X    }
  1068. X}
  1069. X
  1070. Xopen_input(file)
  1071. X    char *file;
  1072. X{
  1073. X    if (file == NULL) {
  1074. X        fin = stdin;
  1075. X        return;
  1076. X    }
  1077. X    infile = file;
  1078. X    fin = fopen(infile,"r");
  1079. X    if (fin == NULL) {
  1080. X        fprintf(stderr,"%s: unable to open ",cmdname);
  1081. X        perror(infile);
  1082. X        crash();    
  1083. X    }
  1084. X}
  1085. X
  1086. X
  1087. Xc_output()
  1088. X{
  1089. X    definition *def;
  1090. X    char *include;    
  1091. X
  1092. X    fprintf(fout,"#include <rpc/rpc.h>\n");
  1093. X    if (infile && (include = extend(infile,".h"))) {
  1094. X        fprintf(fout,"#include \"%s\"\n",include);
  1095. X        free(include);
  1096. X    }
  1097. X    scanprint(OFF);
  1098. X    while (def = get_definition()) {
  1099. X        emit(def);
  1100. X    }
  1101. X}
  1102. X
  1103. Xh_output()
  1104. X{
  1105. X    definition *def;
  1106. X
  1107. X    scanprint(ON);    
  1108. X    while (def = get_definition()) {
  1109. X        print_datadef(def);
  1110. X    }
  1111. X    print_funcdefs();
  1112. X}
  1113. X
  1114. Xs_output(argc,argv)
  1115. X    int argc;
  1116. X    char *argv[];
  1117. X{
  1118. X    char *include;    
  1119. X
  1120. X    scanprint(OFF);
  1121. X    fprintf(fout,"#include <stdio.h>\n");
  1122. X    fprintf(fout,"#include <rpc/rpc.h>\n");
  1123. X    if (infile && (include = extend(infile,".h"))) {
  1124. X        fprintf(fout,"#include \"%s\"\n",include);
  1125. X        free(include);
  1126. X    }
  1127. X    while (get_definition()) 
  1128. X        ;
  1129. X    write_most();
  1130. X    do_registers(argc,argv);    
  1131. X    write_rest();
  1132. X}
  1133. X
  1134. X
  1135. Xdo_registers(argc,argv)
  1136. X    int argc;
  1137. X    char *argv[];
  1138. X{
  1139. X    int i;
  1140. X
  1141. X    for (i = 1; i < argc; i++) {
  1142. X        if (streq(argv[i],"-s")) {
  1143. X            write_register(argv[i+1]);
  1144. X            i++;
  1145. X        }
  1146. X    }
  1147. X}
  1148. X
  1149. Xstatic
  1150. Xparseargs(argc,argv)
  1151. X    int argc;
  1152. X    char *argv[];
  1153. X{
  1154. X    int i;
  1155. X    int j;
  1156. X    char c;
  1157. X    char flag[(1 << 8*sizeof(char))];
  1158. X
  1159. X    if (argc < 2) {
  1160. X        return(0);
  1161. X    }
  1162. X
  1163. X    flag['c'] = 0;
  1164. X    flag['h'] = 0;
  1165. X    flag['s'] = 0;
  1166. X    flag['o'] = 0;
  1167. X    for (i = 1; i < argc; i++) {
  1168. X        if (argv[i][0] != '-') {
  1169. X            if (infile) {
  1170. X                return(0);
  1171. X            }
  1172. X            infile = argv[i];
  1173. X        } else {
  1174. X            for (j = 1; argv[i][j] != 0; j++) {
  1175. X                switch (c = argv[i][j]) {
  1176. X                case 'c':    
  1177. X                case 'h':
  1178. X                    if (flag[c]) {
  1179. X                        return(0);
  1180. X                    }
  1181. X                    flag[c] = 1;    
  1182. X                    break;
  1183. X                case 'o':    
  1184. X                case 's':
  1185. X                    if (argv[i][j-1] != '-' || argv[i][j+1] != 0) {
  1186. X                        return(0);
  1187. X                    }
  1188. X                    flag[c] = 1;
  1189. X                    if (++i == argc) {
  1190. X                        return(0);
  1191. X                    }
  1192. X                    if (c == 's') {
  1193. X                        if (! streq(argv[i],"udp") &&
  1194. X                                ! streq(argv[i],"tcp")) {
  1195. X                            return(0);
  1196. X                        }
  1197. X                    } else if (c == 'o') {
  1198. X                        if (outfile) {
  1199. X                            return(0);
  1200. X                        }
  1201. X                        outfile = argv[i];
  1202. X                    }
  1203. X                    goto nextarg;    
  1204. X    
  1205. X                default:
  1206. X                    return(0);
  1207. X                }
  1208. X            }
  1209. X        nextarg:
  1210. X            ;
  1211. X        }
  1212. X    }
  1213. X    cflag = flag['c'];
  1214. X    hflag = flag['h'];
  1215. X    sflag = flag['s'];
  1216. X    if (! cflag && ! hflag && !sflag && (infile == NULL || outfile != NULL)) {
  1217. X        return(0);
  1218. X    }
  1219. X    return(1);
  1220. X}
  1221. X        
  1222. SHAR_EOF
  1223. if test 4370 -ne "`wc -c < 'rpc/rpcgen/rpc_main.c'`"
  1224. then
  1225.     echo shar: "error transmitting 'rpc/rpcgen/rpc_main.c'" '(should have been 4370 characters)'
  1226. fi
  1227. chmod 444 'rpc/rpcgen/rpc_main.c'
  1228. fi
  1229. echo shar: "extracting 'rpc/rpcgen/rpc_parse.c'" '(8096 characters)'
  1230. if test -f 'rpc/rpcgen/rpc_parse.c'
  1231. then
  1232.     echo shar: "will not over-write existing file 'rpc/rpcgen/rpc_parse.c'"
  1233. else
  1234. sed 's/^X//' << \SHAR_EOF > 'rpc/rpcgen/rpc_parse.c'
  1235. X#ifndef lint 
  1236. Xstatic char sccsid[] = "@(#)rpc_parse.c 1.1 86/03/26 (C) 1986 SMI";
  1237. X#endif
  1238. X
  1239. X/* 
  1240. X * rpc_parse.c, Parser for the RPC protocol compiler
  1241. X * Copyright (C) 1986 Sun Microsystems, Inc.
  1242. X */
  1243. X
  1244. X#include <stdio.h> 
  1245. X#include "rpc_util.h"
  1246. X#include "rpc_scan.h"
  1247. X#include "rpc_parse.h"
  1248. X
  1249. X/*
  1250. X * return the next definition you see
  1251. X */
  1252. Xdefinition *
  1253. Xget_definition()
  1254. X{
  1255. X    definition *defp;
  1256. X    token tok;
  1257. X
  1258. X
  1259. X    defp = ALLOC(definition);
  1260. X    get_token(&tok);
  1261. X    switch (tok.kind) {
  1262. X    case TOK_STRUCT:
  1263. X        def_struct(defp);
  1264. X        break;
  1265. X    case TOK_UNION:
  1266. X        def_union(defp);
  1267. X        break;
  1268. X    case TOK_TYPEDEF:
  1269. X        def_typedef(defp);
  1270. X        break;
  1271. X    case TOK_ARRAY:
  1272. X        def_array(defp);
  1273. X        break;
  1274. X    case TOK_ENUM:
  1275. X        def_enum(defp);
  1276. X        break;
  1277. X    case TOK_PROGRAM:
  1278. X        def_program(defp);    
  1279. X        break;
  1280. X    case TOK_EOF:
  1281. X        return(NULL);    
  1282. X        break;
  1283. X    default:
  1284. X        error("definition keyword expected");
  1285. X    }
  1286. X    scan(TOK_SEMICOLON,&tok);
  1287. X    isdefined(defp);
  1288. X    return(defp);
  1289. X}
  1290. X
  1291. Xstatic 
  1292. Xisdefined(defp)
  1293. X    definition *defp;
  1294. X{
  1295. X    STOREVAL(&defined,defp); 
  1296. X}
  1297. X
  1298. X
  1299. Xstatic
  1300. Xdef_struct(defp)
  1301. X    definition *defp;
  1302. X{
  1303. X    token tok;
  1304. X    declaration dec;
  1305. X    decl_list *decls;
  1306. X    decl_list **tailp;
  1307. X
  1308. X    defp->def_kind = DEF_STRUCT;
  1309. X
  1310. X    scan(TOK_IDENT,&tok);
  1311. X    defp->def_name = tok.str;
  1312. X    scan(TOK_LBRACE,&tok);
  1313. X    tailp = &defp->def.st.decls;
  1314. X    do {
  1315. X        get_declaration(&dec,DEF_STRUCT);
  1316. X        decls = ALLOC(decl_list);
  1317. X        decls->decl = dec;
  1318. X        *tailp = decls;
  1319. X        tailp = &decls->next;
  1320. X        scan(TOK_SEMICOLON,&tok);
  1321. X        peek(&tok);    
  1322. X    } while (tok.kind != TOK_RBRACE);
  1323. X    get_token(&tok);    
  1324. X    *tailp = NULL;    
  1325. X}
  1326. X
  1327. Xstatic
  1328. Xdef_program(defp)
  1329. X    definition *defp;
  1330. X{
  1331. X    token tok;
  1332. X    version_list *vlist;
  1333. X    version_list **vtailp;
  1334. X    proc_list *plist;
  1335. X    proc_list **ptailp;
  1336. X    
  1337. X    defp->def_kind = DEF_PROGRAM;
  1338. X    scan(TOK_IDENT,&tok);
  1339. X    defp->def_name = tok.str;
  1340. X    scan(TOK_LBRACE,&tok);
  1341. X    vtailp = &defp->def.pr.versions;
  1342. X    scan(TOK_VERSION,&tok);
  1343. X    do {
  1344. X        scan(TOK_IDENT,&tok);
  1345. X        vlist = ALLOC(version_list);
  1346. X        vlist->vers_name = tok.str;
  1347. X        scan(TOK_LBRACE,&tok);
  1348. X        ptailp = &vlist->procs;
  1349. X        do {
  1350. X            plist = ALLOC(proc_list);
  1351. X            get_type(&plist->res_prefix,&plist->res_type,DEF_PROGRAM);
  1352. X            if (streq(plist->res_type,"string") || 
  1353. X                    streq(plist->res_type,"opaque")) {
  1354. X                error("illegal result type");
  1355. X            }
  1356. X            scan(TOK_IDENT,&tok);
  1357. X            plist->proc_name = tok.str;
  1358. X            scan(TOK_LPAREN,&tok);
  1359. X            get_type(&plist->arg_prefix,&plist->arg_type,DEF_PROGRAM);
  1360. X            if (streq(plist->arg_type,"string") || 
  1361. X                    streq(plist->arg_type,"opaque")) {
  1362. X                error("illegal argument type");
  1363. X            }
  1364. X            scan(TOK_RPAREN,&tok);
  1365. X            scan(TOK_EQUAL,&tok);
  1366. X            scan_num(&tok);
  1367. X            scan(TOK_SEMICOLON,&tok);
  1368. X            plist->proc_num = tok.str;
  1369. X            *ptailp = plist;
  1370. X            ptailp = &plist->next;
  1371. X            peek(&tok);
  1372. X        } while (tok.kind != TOK_RBRACE);
  1373. X        *vtailp = vlist;
  1374. X        vtailp = &vlist->next;
  1375. X        scan(TOK_RBRACE,&tok);
  1376. X        scan(TOK_EQUAL,&tok);
  1377. X        scan_num(&tok);
  1378. X        vlist->vers_num = tok.str;
  1379. X        scan(TOK_SEMICOLON,&tok);
  1380. X        scan2(TOK_VERSION,TOK_RBRACE,&tok);
  1381. X    } while (tok.kind == TOK_VERSION);
  1382. X    scan(TOK_EQUAL, &tok);
  1383. X    scan_num(&tok);
  1384. X    defp->def.pr.prog_num = tok.str;
  1385. X    *vtailp = NULL;
  1386. X}
  1387. X    
  1388. Xstatic    
  1389. Xdef_enum(defp)
  1390. X    definition *defp;
  1391. X{
  1392. X    token tok;
  1393. X    enumval_list *elist;
  1394. X    enumval_list **tailp;
  1395. X
  1396. X    defp->def_kind = DEF_ENUM;
  1397. X    scan(TOK_IDENT,&tok);
  1398. X    defp->def_name = tok.str;
  1399. X    scan(TOK_LBRACE,&tok);
  1400. X    tailp = &defp->def.en.vals;
  1401. X    do {
  1402. X        scan(TOK_IDENT,&tok);
  1403. X        elist = ALLOC(enumval_list);
  1404. X        elist->name = tok.str;
  1405. X        elist->assignment = NULL;
  1406. X        scan3(TOK_COMMA,TOK_RBRACE,TOK_EQUAL,&tok);    
  1407. X        if (tok.kind == TOK_EQUAL) {
  1408. X            scan_num(&tok);
  1409. X            elist->assignment = tok.str;
  1410. X            scan2(TOK_COMMA,TOK_RBRACE,&tok);
  1411. X        }
  1412. X        *tailp = elist;
  1413. X        tailp = &elist->next;
  1414. X    } while (tok.kind != TOK_RBRACE);
  1415. X    *tailp = NULL;
  1416. X}
  1417. X    
  1418. Xstatic
  1419. Xdef_array(defp)
  1420. X    definition *defp;
  1421. X{
  1422. X    token tok;
  1423. X    declaration dec;
  1424. X
  1425. X    defp->def_kind = DEF_ARRAY;
  1426. X    scan(TOK_IDENT,&tok);
  1427. X    defp->def_name = tok.str;
  1428. X    scan(TOK_LBRACE,&tok);
  1429. X    get_declaration(&dec,DEF_ARRAY);
  1430. X    if (! streq(dec.type,"u_int")) {
  1431. X        error("array length must be of type unsigned");
  1432. X    }
  1433. X    if (dec.rel != REL_ALIAS) {
  1434. X        error("array length may not be pointer or vector");
  1435. X    }
  1436. X    scan(TOK_SEMICOLON,&tok);
  1437. X    defp->def.ar.len_name = dec.name;
  1438. X    get_declaration(&dec,DEF_ARRAY);
  1439. X    if (dec.rel != REL_VECTOR) {
  1440. X        error("expected array declaration");
  1441. X    }
  1442. X    if (streq(dec.type,"string")) {
  1443. X        error("string declarations don't make sense here");
  1444. X    }
  1445. X    scan(TOK_SEMICOLON,&tok);
  1446. X    defp->def.ar.array_prefix = dec.prefix;
  1447. X    defp->def.ar.array_type = dec.type;
  1448. X    defp->def.ar.array_name = dec.name;
  1449. X    defp->def.ar.array_max = dec.array_max;
  1450. X    scan(TOK_RBRACE,&tok);
  1451. X}
  1452. X
  1453. X
  1454. X
  1455. Xstatic
  1456. Xdef_union(defp)
  1457. X    definition *defp;
  1458. X{ 
  1459. X    token tok;
  1460. X    declaration dec;
  1461. X    case_list *cases;
  1462. X    case_list **tailp;
  1463. X
  1464. X    defp->def_kind = DEF_UNION;
  1465. X    scan(TOK_IDENT,&tok);
  1466. X    defp->def_name = tok.str;
  1467. X    scan(TOK_SWITCH,&tok);
  1468. X    scan(TOK_LPAREN,&tok);
  1469. X    get_declaration(&dec,DEF_UNION);
  1470. X    defp->def.un.enum_decl = dec;
  1471. X    tailp = &defp->def.un.cases;
  1472. X    scan(TOK_RPAREN,&tok);
  1473. X    scan(TOK_LBRACE,&tok);
  1474. X    scan(TOK_CASE, &tok);
  1475. X    while (tok.kind == TOK_CASE) {
  1476. X        scan(TOK_IDENT,&tok);
  1477. X        cases = ALLOC(case_list);
  1478. X        cases->case_name = tok.str;
  1479. X        scan(TOK_COLON,&tok);
  1480. X        get_declaration(&dec,DEF_UNION);
  1481. X        cases->case_decl = dec;
  1482. X        *tailp = cases;
  1483. X        tailp = &cases->next;
  1484. X        scan(TOK_SEMICOLON,&tok);
  1485. X        scan3(TOK_CASE,TOK_DEFAULT,TOK_RBRACE,&tok);
  1486. X    }
  1487. X    *tailp = NULL;
  1488. X    if (tok.kind == TOK_DEFAULT) {
  1489. X        scan(TOK_COLON,&tok);
  1490. X        get_declaration(&dec,DEF_UNION);
  1491. X        defp->def.un.default_decl =  ALLOC(declaration);
  1492. X        *defp->def.un.default_decl = dec;
  1493. X        scan(TOK_SEMICOLON,&tok);
  1494. X        scan(TOK_RBRACE,&tok);
  1495. X    }
  1496. X}
  1497. X
  1498. X
  1499. Xstatic
  1500. Xdef_typedef(defp)
  1501. X    definition *defp;
  1502. X{ 
  1503. X    declaration dec;
  1504. X
  1505. X    defp->def_kind = DEF_TYPEDEF;
  1506. X    get_declaration(&dec,DEF_TYPEDEF);
  1507. X    defp->def_name = dec.name;
  1508. X    defp->def.ty.old_prefix = dec.prefix;
  1509. X    defp->def.ty.old_type = dec.type;
  1510. X    defp->def.ty.rel = dec.rel;
  1511. X    defp->def.ty.array_max = dec.array_max;
  1512. X}
  1513. X
  1514. X
  1515. Xstatic
  1516. Xget_declaration(dec,dkind)
  1517. X    declaration *dec;
  1518. X    defkind dkind;
  1519. X{
  1520. X    token tok;
  1521. X
  1522. X    get_type(&dec->prefix,&dec->type,dkind);
  1523. X    dec->rel = REL_ALIAS;
  1524. X    scan2(TOK_STAR,TOK_IDENT,&tok);
  1525. X    if (tok.kind == TOK_STAR) {
  1526. X        dec->rel = REL_POINTER;
  1527. X        scan(TOK_IDENT,&tok);
  1528. X    }
  1529. X    dec->name = tok.str; 
  1530. X    if (peekscan(TOK_LBRACKET,&tok)) {
  1531. X        if (dec->rel == REL_POINTER) {
  1532. X            error("no array-of-pointer declarations -- use typedef");
  1533. X        }
  1534. X        dec->rel = REL_VECTOR;
  1535. X        if (streq(dec->type,"string") && peekscan(TOK_RBRACKET,&tok)) {
  1536. X            dec->array_max = NULL;     /* means unspecified */
  1537. X        } else {    
  1538. X            dec->rel = REL_VECTOR;
  1539. X            scan_num(&tok);    
  1540. X            dec->array_max = tok.str;
  1541. X            scan(TOK_RBRACKET,&tok);
  1542. X        }
  1543. X    }
  1544. X    if (streq(dec->type,"opaque") || streq(dec->type,"string")) {
  1545. X        if (dec->rel != REL_VECTOR) {
  1546. X            error("vector declaration expected");
  1547. X        }
  1548. X    } else if (streq(dec->type,"void")) {
  1549. X        if (dec->rel != REL_ALIAS) {
  1550. X            error("no vector-of-void or pointer-to-void declarations");
  1551. X        }
  1552. X    }
  1553. X}
  1554. X
  1555. X
  1556. Xstatic
  1557. Xget_type(prefixp,typep, dkind)
  1558. X    char **prefixp;
  1559. X    char **typep;
  1560. X    defkind dkind;
  1561. X{
  1562. X    token tok;
  1563. X
  1564. X    *prefixp = NULL; 
  1565. X    get_token(&tok);
  1566. X    switch (tok.kind) {
  1567. X    case TOK_IDENT:
  1568. X        *typep = tok.str;
  1569. X        break;
  1570. X    case TOK_STRUCT:
  1571. X    case TOK_ENUM:
  1572. X    case TOK_ARRAY:
  1573. X    case TOK_UNION:
  1574. X        *prefixp = tok.str;
  1575. X        scan(TOK_IDENT,&tok);    
  1576. X        *typep = tok.str;
  1577. X        break;
  1578. X    case TOK_UNSIGNED:
  1579. X        unsigned_dec(typep);
  1580. X        break;
  1581. X    case TOK_SHORT:
  1582. X        *typep = "short"; 
  1583. X        (void) peekscan(TOK_INT,&tok);
  1584. X        break;
  1585. X    case TOK_LONG:
  1586. X        *typep = "long"; 
  1587. X        (void) peekscan(TOK_INT,&tok);
  1588. X        break;
  1589. X    case TOK_VOID:
  1590. X        if (dkind != DEF_UNION && dkind != DEF_PROGRAM) {
  1591. X            error("voids allowed only inside union and program definitions");
  1592. X        }
  1593. X        *typep = tok.str;
  1594. X        break;
  1595. X    case TOK_STRING:
  1596. X    case TOK_OPAQUE:
  1597. X    case TOK_CHAR:
  1598. X    case TOK_INT:
  1599. X    case TOK_FLOAT:
  1600. X    case TOK_DOUBLE:
  1601. X    case TOK_BOOL:
  1602. X        *typep = tok.str;
  1603. X        break;    
  1604. X    default:
  1605. X        error("expected type specifier");
  1606. X    }
  1607. X}
  1608. X
  1609. X
  1610. Xstatic
  1611. Xunsigned_dec(typep)
  1612. X    char **typep;
  1613. X{
  1614. X    token tok;
  1615. X
  1616. X    peek(&tok);
  1617. X    switch (tok.kind) {
  1618. X    case TOK_CHAR:
  1619. X        get_token(&tok);
  1620. X        *typep = "u_char";
  1621. X        break;
  1622. X    case TOK_SHORT:
  1623. X        get_token(&tok);
  1624. X        *typep = "u_short";
  1625. X        (void) peekscan(TOK_INT,&tok);
  1626. X        break;
  1627. X    case TOK_LONG:
  1628. X        get_token(&tok);
  1629. X        *typep = "u_long";
  1630. X        (void) peekscan(TOK_INT,&tok);
  1631. X        break;
  1632. X    case TOK_INT:
  1633. X        get_token(&tok);
  1634. X        *typep = "u_int";
  1635. X        break;
  1636. X    default:
  1637. X        *typep = "u_int";
  1638. X        break;
  1639. X    }
  1640. X}
  1641. SHAR_EOF
  1642. if test 8096 -ne "`wc -c < 'rpc/rpcgen/rpc_parse.c'`"
  1643. then
  1644.     echo shar: "error transmitting 'rpc/rpcgen/rpc_parse.c'" '(should have been 8096 characters)'
  1645. fi
  1646. chmod 444 'rpc/rpcgen/rpc_parse.c'
  1647. fi
  1648. echo shar: "extracting 'rpc/rpcgen/rpc_parse.h'" '(2141 characters)'
  1649. if test -f 'rpc/rpcgen/rpc_parse.h'
  1650. then
  1651.     echo shar: "will not over-write existing file 'rpc/rpcgen/rpc_parse.h'"
  1652. else
  1653. sed 's/^X//' << \SHAR_EOF > 'rpc/rpcgen/rpc_parse.h'
  1654. X/* @(#)rpc_parse.h 1.1 86/03/26 (C) 1986 SMI */
  1655. X
  1656. X/*
  1657. X * rpc_parse.h, Definitions for the RPCL parser 
  1658. X * Copyright (C) 1986, Sun Microsystems, Inc.
  1659. X */
  1660. X
  1661. Xenum defkind {
  1662. X    DEF_ARRAY,
  1663. X    DEF_STRUCT,
  1664. X    DEF_UNION,
  1665. X    DEF_ENUM,
  1666. X    DEF_TYPEDEF,
  1667. X    DEF_PROGRAM
  1668. X};
  1669. Xtypedef enum defkind defkind;
  1670. X
  1671. Xstruct array_def {
  1672. X    char *len_name;
  1673. X    char *array_name;
  1674. X    char *array_prefix;
  1675. X    char *array_type;
  1676. X    char *array_max;    
  1677. X};
  1678. Xtypedef struct array_def array_def;
  1679. X
  1680. Xenum relation {
  1681. X    REL_VECTOR,
  1682. X    REL_POINTER,
  1683. X    REL_ALIAS,
  1684. X};
  1685. Xtypedef enum relation relation;
  1686. X
  1687. Xstruct typedef_def {
  1688. X    char *old_prefix;
  1689. X    char *old_type;
  1690. X    relation rel;
  1691. X    char *array_max;
  1692. X};
  1693. Xtypedef struct typedef_def typedef_def;
  1694. X
  1695. X
  1696. Xstruct enumval_list {
  1697. X    char *name;
  1698. X    char *assignment;
  1699. X    struct enumval_list *next;
  1700. X};
  1701. Xtypedef struct enumval_list enumval_list;
  1702. X
  1703. Xstruct enum_def {
  1704. X    enumval_list *vals;
  1705. X};
  1706. Xtypedef struct enum_def enum_def;
  1707. X
  1708. X
  1709. Xstruct declaration {
  1710. X    char *prefix;
  1711. X    char *type;
  1712. X    char *name;
  1713. X    relation rel;
  1714. X    char *array_max;
  1715. X};
  1716. Xtypedef struct declaration declaration;
  1717. X
  1718. X
  1719. Xstruct decl_list {
  1720. X    declaration decl;
  1721. X    struct decl_list *next;
  1722. X};
  1723. Xtypedef struct decl_list decl_list;
  1724. X
  1725. Xstruct struct_def {
  1726. X    decl_list *decls;
  1727. X};
  1728. Xtypedef struct struct_def struct_def;
  1729. X
  1730. X
  1731. Xstruct case_list {
  1732. X    char *case_name;
  1733. X    declaration case_decl;
  1734. X    struct case_list *next;
  1735. X};
  1736. Xtypedef struct case_list case_list;
  1737. X
  1738. Xstruct union_def {
  1739. X    declaration enum_decl;
  1740. X    case_list *cases;
  1741. X    declaration *default_decl;
  1742. X};
  1743. Xtypedef struct union_def union_def;
  1744. X
  1745. X
  1746. X
  1747. Xstruct proc_list {
  1748. X    char *proc_name;
  1749. X    char *proc_num;
  1750. X    char *arg_type;
  1751. X    char *arg_prefix;
  1752. X    char *res_type;
  1753. X    char *res_prefix;
  1754. X    struct proc_list *next;
  1755. X};
  1756. Xtypedef struct proc_list proc_list;
  1757. X
  1758. X
  1759. Xstruct version_list {
  1760. X    char *vers_name;
  1761. X    char *vers_num;    
  1762. X    proc_list *procs;
  1763. X    struct version_list *next;
  1764. X};
  1765. Xtypedef struct version_list version_list;
  1766. X
  1767. Xstruct program_def {    
  1768. X    char *prog_num;
  1769. X    version_list *versions;
  1770. X};
  1771. Xtypedef struct program_def program_def;
  1772. X
  1773. Xstruct definition {
  1774. X    char *def_name;
  1775. X    defkind def_kind;
  1776. X    union {
  1777. X        array_def ar;
  1778. X        struct_def st;
  1779. X        union_def un;
  1780. X        enum_def en;
  1781. X        typedef_def ty;
  1782. X        program_def pr;
  1783. X    } def;
  1784. X};
  1785. Xtypedef struct definition definition;
  1786. X
  1787. Xdefinition *get_definition();
  1788. SHAR_EOF
  1789. if test 2141 -ne "`wc -c < 'rpc/rpcgen/rpc_parse.h'`"
  1790. then
  1791.     echo shar: "error transmitting 'rpc/rpcgen/rpc_parse.h'" '(should have been 2141 characters)'
  1792. fi
  1793. chmod 444 'rpc/rpcgen/rpc_parse.h'
  1794. fi
  1795. echo shar: "extracting 'rpc/rpcgen/rpc_scan.c'" '(5877 characters)'
  1796. if test -f 'rpc/rpcgen/rpc_scan.c'
  1797. then
  1798.     echo shar: "will not over-write existing file 'rpc/rpcgen/rpc_scan.c'"
  1799. else
  1800. sed 's/^X//' << \SHAR_EOF > 'rpc/rpcgen/rpc_scan.c'
  1801. X#ifndef lint 
  1802. Xstatic char sccsid[] = "@(#)rpc_scan.c 1.1 86/03/26 (C) 1986 SMI";
  1803. X#endif
  1804. X/*
  1805. X * rpc_scan.c, Scanner for the RPC protocol compiler
  1806. X * Copyright (C) 1986, Sun Microsystems, Inc.
  1807. X */
  1808. X
  1809. X#include <stdio.h>
  1810. X#include <ctype.h>
  1811. X#include <strings.h>
  1812. X#include "rpc_scan.h"
  1813. X#include "rpc_util.h"
  1814. X
  1815. X#define commentstart(p)    (*(p) == '/' && *((p) + 1) == '*')
  1816. X#define commentend(p)    (*(p) == '*' && *((p) + 1) == '/') 
  1817. X
  1818. Xstatic int pushed = 0;            /* is a token pushed */
  1819. Xstatic token lasttok;            /* last token, if pushed */
  1820. Xstatic int scan_print;            /* print out directives? */
  1821. X
  1822. X/*
  1823. X * turn printing on or off
  1824. X */
  1825. Xvoid
  1826. Xscanprint(sw) 
  1827. X    int sw; 
  1828. X{
  1829. X    scan_print = sw;
  1830. X}
  1831. X
  1832. X
  1833. X/*
  1834. X * scan expecting 1 given token
  1835. X */
  1836. Xvoid
  1837. Xscan(expect,tokp)
  1838. X    tok_kind expect;
  1839. X    token *tokp;
  1840. X{
  1841. X    get_token(tokp);
  1842. X    if (tokp->kind != expect) {
  1843. X        expected1(expect);
  1844. X    }
  1845. X}
  1846. X
  1847. X/*
  1848. X * scan expecting 2 given tokens
  1849. X */
  1850. Xvoid
  1851. Xscan2(expect1,expect2,tokp)
  1852. X    tok_kind expect1;
  1853. X    tok_kind expect2;
  1854. X    token *tokp;
  1855. X{
  1856. X    get_token(tokp);
  1857. X    if (tokp->kind != expect1 && tokp->kind != expect2) {
  1858. X        expected2(expect1,expect2);
  1859. X    }
  1860. X}
  1861. X
  1862. X/*
  1863. X * scan expecting 3 given token
  1864. X */
  1865. Xvoid
  1866. Xscan3(expect1,expect2,expect3,tokp)
  1867. X    tok_kind expect1;
  1868. X    tok_kind expect2;
  1869. X    tok_kind expect3;
  1870. X    token *tokp;
  1871. X{
  1872. X    get_token(tokp);
  1873. X    if (tokp->kind != expect1 && tokp->kind != expect2 
  1874. X            && tokp->kind != expect3) {
  1875. X        expected3(expect1,expect2,expect3);
  1876. X    }
  1877. X}
  1878. X
  1879. X
  1880. X/*
  1881. X * scan expecting a constant, possibly symbolic
  1882. X */
  1883. Xvoid
  1884. Xscan_num(tokp)
  1885. X    token *tokp;
  1886. X{
  1887. X    get_token(tokp);
  1888. X    switch (tokp->kind) {
  1889. X    case TOK_CONST:    
  1890. X    case TOK_IDENT:
  1891. X        break;    
  1892. X    default:
  1893. X        error("constant or identifier expected");
  1894. X    }
  1895. X}
  1896. X
  1897. X
  1898. X/*
  1899. X * Peek at the next token
  1900. X */
  1901. Xvoid
  1902. Xpeek(tokp)
  1903. X    token *tokp;
  1904. X{
  1905. X    get_token(tokp);
  1906. X    unget_token(tokp);
  1907. X}
  1908. X
  1909. X
  1910. X/*
  1911. X * Peek at the next token and
  1912. X * scan it if it matches what you expect
  1913. X */
  1914. Xint
  1915. Xpeekscan(expect,tokp)
  1916. X    tok_kind expect;
  1917. X    token *tokp;
  1918. X{
  1919. X    peek(tokp);
  1920. X    if (tokp->kind == expect) {
  1921. X        get_token(tokp);
  1922. X        return(1);
  1923. X    }
  1924. X    return(0);
  1925. X}
  1926. X
  1927. X
  1928. X
  1929. X/*
  1930. X * Get the next token, printing out any directive that
  1931. X * are encountered.
  1932. X */
  1933. Xvoid
  1934. Xget_token(tokp)
  1935. X    token *tokp;
  1936. X{
  1937. X
  1938. X    if (pushed) {
  1939. X        pushed = 0;
  1940. X        *tokp = lasttok;
  1941. X        return;
  1942. X    }
  1943. X    for (;;) {    
  1944. X        if (*where == 0) {
  1945. X            if (! fgets(curline,MAXLINESIZE,fin)) {
  1946. X                tokp->kind = TOK_EOF;
  1947. X                *where = 0;
  1948. X                return;
  1949. X            }
  1950. X            where = curline;
  1951. X            linenum++;
  1952. X        } else if (isspace(*where)) {
  1953. X            whitespace();
  1954. X        } else if (commentstart(where)) {
  1955. X            decomment();
  1956. X        } else if (directive(where)) {
  1957. X            printdirective(where);
  1958. X            *where = 0;
  1959. X        } else {
  1960. X            break;
  1961. X        }
  1962. X    }
  1963. X    /* 
  1964. X     * 'where' is not whitespace, comment, or directive
  1965. X     * Must be a token!
  1966. X     */
  1967. X    switch (*where) {
  1968. X    case ':':    tokp->kind = TOK_COLON; where++; break;    
  1969. X    case ';':    tokp->kind = TOK_SEMICOLON; where++; break;
  1970. X    case ',':    tokp->kind = TOK_COMMA; where++; break;
  1971. X    case '=':    tokp->kind = TOK_EQUAL; where++; break;
  1972. X    case '*':    tokp->kind = TOK_STAR; where++; break;
  1973. X    case '[':    tokp->kind = TOK_LBRACKET; where++; break;
  1974. X    case ']':    tokp->kind = TOK_RBRACKET; where++; break;
  1975. X    case '{':    tokp->kind = TOK_LBRACE; where++; break;
  1976. X    case '}':    tokp->kind = TOK_RBRACE; where++; break;
  1977. X    case '(':    tokp->kind = TOK_LPAREN; where++; break;
  1978. X    case ')':    tokp->kind = TOK_RPAREN; where++; break;
  1979. X
  1980. X    case '0':      
  1981. X    case '1': 
  1982. X    case '2':
  1983. X    case '3':
  1984. X    case '4':
  1985. X    case '5':
  1986. X    case '6':
  1987. X    case '7':
  1988. X    case '8':
  1989. X    case '9':
  1990. X        tokp->kind = TOK_CONST; 
  1991. X        findconst(&where,&tokp->str);
  1992. X        break;
  1993. X
  1994. X
  1995. X    default:
  1996. X        if ( ! (isalpha(*where) || *where == '_')) {
  1997. X            char buf[100];
  1998. X            char *p;
  1999. X
  2000. X            sprintf(buf,"illegal character in file: ");
  2001. X            p = buf + strlen(buf);
  2002. X            if (isprint(*where)) {
  2003. X                sprintf(p,"%c",*where);    
  2004. X            } else {
  2005. X                sprintf(p,"%d",*where);
  2006. X            }
  2007. X            error(buf);
  2008. X        }
  2009. X        findkind(&where,tokp);
  2010. X        break;
  2011. X    }
  2012. X}
  2013. X
  2014. X
  2015. X
  2016. Xstatic
  2017. Xunget_token(tokp)
  2018. X    token *tokp;
  2019. X{
  2020. X    lasttok = *tokp;
  2021. X    pushed = 1;
  2022. X}
  2023. X
  2024. X
  2025. Xstatic
  2026. Xfindconst(str,val)
  2027. X    char **str;
  2028. X    char **val;
  2029. X{
  2030. X    char *p;
  2031. X    int size;
  2032. X
  2033. X    p = *str;
  2034. X    do {
  2035. X        *p++;
  2036. X    } while (isdigit(*p));
  2037. X    size = p - *str;
  2038. X    *val = alloc(size + 1);
  2039. X    strncpy(*val,*str,size);
  2040. X    (*val)[size] = 0;
  2041. X    *str = p;
  2042. X}
  2043. X
  2044. X
  2045. X
  2046. Xstatic token symbols[] = {
  2047. X    { TOK_UNION,    "union" },
  2048. X    { TOK_SWITCH,    "switch" }, 
  2049. X    { TOK_CASE,    "case" },
  2050. X    { TOK_DEFAULT,    "default" },
  2051. X    { TOK_STRUCT,        "struct" },
  2052. X    { TOK_TYPEDEF,    "typedef" },
  2053. X    { TOK_ENUM,    "enum" },
  2054. X    { TOK_ARRAY,    "array" },
  2055. X    { TOK_OPAQUE,    "opaque" },
  2056. X    { TOK_BOOL,    "bool" },
  2057. X    { TOK_VOID,    "void" },
  2058. X    { TOK_CHAR,    "char" },
  2059. X    { TOK_INT,    "int" },
  2060. X    { TOK_UNSIGNED,    "unsigned" },
  2061. X    { TOK_SHORT,    "short" },
  2062. X    { TOK_LONG,    "long" },
  2063. X    { TOK_FLOAT,    "float" },
  2064. X    { TOK_DOUBLE,    "double" },
  2065. X    { TOK_STRING,    "string" },
  2066. X    { TOK_PROGRAM,    "program" },
  2067. X    { TOK_VERSION,    "version" },
  2068. X    { TOK_EOF,    "??????"},
  2069. X};
  2070. X
  2071. X
  2072. Xstatic
  2073. Xfindkind(mark,tokp)
  2074. X    char **mark;
  2075. X    token *tokp;
  2076. X{
  2077. X
  2078. X    int len;
  2079. X    token *s;
  2080. X    char *str;
  2081. X
  2082. X    str = *mark;
  2083. X    for (s = symbols; s->kind != TOK_EOF; s++) {
  2084. X        len = strlen(s->str);
  2085. X        if (strncmp(str,s->str,len) == 0) {
  2086. X            if (!isalnum(str[len]) && str[len] != '_') {
  2087. X                tokp->kind = s->kind;
  2088. X                tokp->str = s->str;
  2089. X                *mark = str + len;
  2090. X                return;    
  2091. X            }
  2092. X        }
  2093. X    }
  2094. X    tokp->kind = TOK_IDENT;
  2095. X    for (len = 0; isalnum(str[len]) || str[len] == '_'; len++)
  2096. X        ;
  2097. X    tokp->str = alloc(len+1);
  2098. X    strncpy(tokp->str,str,len);
  2099. X    tokp->str[len] = 0;
  2100. X    *mark = str + len;
  2101. X}
  2102. X
  2103. Xstatic
  2104. Xwhitespace()
  2105. X{
  2106. X    while (isspace(*where))
  2107. X        where++;
  2108. X}
  2109. X
  2110. Xstatic
  2111. Xdecomment()
  2112. X{
  2113. X    for (where += 2; ! commentend(where) ; where++) {
  2114. X        if (*where == 0) {
  2115. X            if (! fgets(curline,MAXLINESIZE,fin)) {
  2116. X                error("unterminated comment");
  2117. X            }
  2118. X            linenum++;
  2119. X            where = curline - 1;
  2120. X        }
  2121. X    }
  2122. X    where += 2;
  2123. X}
  2124. X
  2125. X
  2126. Xstatic
  2127. Xdirective(line)
  2128. X    char *line;
  2129. X{
  2130. X    return(line == curline && *line == '#');
  2131. X}
  2132. Xstatic
  2133. Xprintdirective(line)
  2134. X    char *line;
  2135. X{
  2136. X    char *s;
  2137. X
  2138. X    for (s = line + strlen(line) - 1; s >= line; s--) {
  2139. X        if (commentend(s)) {
  2140. X            break;    
  2141. X        } else if (commentstart(s)) {
  2142. X            where = s;
  2143. X            *where++ = '\n';
  2144. X            *where = 0;    
  2145. X            if (scan_print) {
  2146. X                fprintf(fout,line);
  2147. X            }
  2148. X            decomment();
  2149. X            return;
  2150. X        } 
  2151. X    }
  2152. X    if (scan_print) {
  2153. X        fprintf(fout,line);
  2154. X    }
  2155. X}                
  2156. SHAR_EOF
  2157. if test 5877 -ne "`wc -c < 'rpc/rpcgen/rpc_scan.c'`"
  2158. then
  2159.     echo shar: "error transmitting 'rpc/rpcgen/rpc_scan.c'" '(should have been 5877 characters)'
  2160. fi
  2161. chmod 444 'rpc/rpcgen/rpc_scan.c'
  2162. fi
  2163. echo shar: "extracting 'rpc/rpcgen/rpc_scan.h'" '(914 characters)'
  2164. if test -f 'rpc/rpcgen/rpc_scan.h'
  2165. then
  2166.     echo shar: "will not over-write existing file 'rpc/rpcgen/rpc_scan.h'"
  2167. else
  2168. sed 's/^X//' << \SHAR_EOF > 'rpc/rpcgen/rpc_scan.h'
  2169. X/* @(#)rpc_scan.h 1.1 86/03/26 (C) 1986 SMI */
  2170. X
  2171. X/*
  2172. X * rpc_scan.h, Definitions for the RPCL scanner
  2173. X * Copyright (C) 1986, Sun Microsystems, Inc.
  2174. X */
  2175. X
  2176. X/*
  2177. X * kinds of tokens
  2178. X */
  2179. Xenum tok_kind {
  2180. X    TOK_IDENT,
  2181. X    TOK_CONST,
  2182. X    TOK_LPAREN,
  2183. X    TOK_RPAREN,
  2184. X    TOK_LBRACE,
  2185. X    TOK_RBRACE,
  2186. X    TOK_LBRACKET,
  2187. X    TOK_RBRACKET,
  2188. X    TOK_STAR,
  2189. X    TOK_COMMA,
  2190. X    TOK_EQUAL,
  2191. X    TOK_COLON,
  2192. X    TOK_SEMICOLON,
  2193. X    TOK_STRUCT,
  2194. X    TOK_UNION,
  2195. X    TOK_SWITCH,
  2196. X    TOK_CASE,
  2197. X    TOK_DEFAULT,
  2198. X    TOK_ENUM,
  2199. X    TOK_ARRAY,
  2200. X    TOK_TYPEDEF,
  2201. X    TOK_INT,
  2202. X    TOK_SHORT,
  2203. X    TOK_LONG,
  2204. X    TOK_UNSIGNED,
  2205. X    TOK_FLOAT,
  2206. X    TOK_DOUBLE,
  2207. X    TOK_OPAQUE,
  2208. X    TOK_CHAR,
  2209. X    TOK_STRING,
  2210. X    TOK_BOOL,
  2211. X    TOK_VOID,
  2212. X    TOK_PROGRAM,
  2213. X    TOK_VERSION,
  2214. X    TOK_EOF
  2215. X};
  2216. Xtypedef enum tok_kind tok_kind;
  2217. X
  2218. X/*
  2219. X * a token
  2220. X */
  2221. Xstruct token {
  2222. X    tok_kind kind;
  2223. X    char *str;
  2224. X};
  2225. Xtypedef struct token token;
  2226. X
  2227. X
  2228. X/*
  2229. X * routine interface
  2230. X */
  2231. Xvoid scanprint();    
  2232. Xvoid scan();
  2233. Xvoid scan2();
  2234. Xvoid scan3();
  2235. Xvoid scan_num();
  2236. Xvoid peek();
  2237. Xint  peekscan();
  2238. Xvoid get_token();
  2239. X
  2240. SHAR_EOF
  2241. if test 914 -ne "`wc -c < 'rpc/rpcgen/rpc_scan.h'`"
  2242. then
  2243.     echo shar: "error transmitting 'rpc/rpcgen/rpc_scan.h'" '(should have been 914 characters)'
  2244. fi
  2245. chmod 444 'rpc/rpcgen/rpc_scan.h'
  2246. fi
  2247. echo shar: "extracting 'rpc/rpcgen/rpc_svcout.c'" '(5764 characters)'
  2248. if test -f 'rpc/rpcgen/rpc_svcout.c'
  2249. then
  2250.     echo shar: "will not over-write existing file 'rpc/rpcgen/rpc_svcout.c'"
  2251. else
  2252. sed 's/^X//' << \SHAR_EOF > 'rpc/rpcgen/rpc_svcout.c'
  2253. X#ifndef lint 
  2254. Xstatic char sccsid[] = "@(#)rpc_svcout.c 1.1 86/03/26 (C) 1986 SMI";
  2255. X#endif
  2256. X
  2257. X/*
  2258. X * rpc_svcout.c, Server-skeleton outputter for the RPC protocol compiler
  2259. X * Copyright (C) 1986, Sun Microsytsems, Inc.
  2260. X */
  2261. X#include <stdio.h>
  2262. X#include <strings.h>
  2263. X#include "rpc_parse.h"
  2264. X#include "rpc_util.h"
  2265. X
  2266. Xstatic char RQSTP[] = "rqstp";
  2267. Xstatic char TRANSP[] = "transp";
  2268. Xstatic char ARG[] = "argument";
  2269. Xstatic char RESULT[] = "result";
  2270. Xstatic char ROUTINE[] = "local";
  2271. X
  2272. X
  2273. X/*
  2274. X * write most of the service, that is,
  2275. X * everything but the registrations.
  2276. X */
  2277. Xvoid
  2278. Xwrite_most()
  2279. X{
  2280. X    list *l;
  2281. X    definition *def;
  2282. X    version_list *vp;
  2283. X
  2284. X
  2285. X    for (l = defined; l != NULL; l = l->next) {
  2286. X        def = (definition *) l->val;
  2287. X        if (def->def_kind == DEF_PROGRAM) {
  2288. X            write_program(def);
  2289. X        }
  2290. X    }
  2291. X    fprintf(fout,"\n\n");
  2292. X    fprintf(fout,"main()\n");
  2293. X    fprintf(fout,"{\n");
  2294. X    fprintf(fout,"\tSVCXPRT *%s;\n",TRANSP);
  2295. X    fprintf(fout,"\n");
  2296. X    for (l = defined; l != NULL; l = l->next) {
  2297. X        def = (definition *) l->val;
  2298. X        if (def->def_kind != DEF_PROGRAM) {    
  2299. X            continue;
  2300. X        }
  2301. X        for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
  2302. X             fprintf(fout,"\tpmap_unset(%s, %s);\n",def->def_name,vp->vers_name);
  2303. X        }
  2304. X    }
  2305. X}
  2306. X
  2307. X
  2308. X/*
  2309. X * write a registration for the given transport
  2310. X */
  2311. Xvoid
  2312. Xwrite_register(transp)
  2313. X    char *transp;
  2314. X{
  2315. X    list *l;
  2316. X    definition *def;
  2317. X    version_list *vp;
  2318. X
  2319. X    fprintf(fout,"\n");
  2320. X    fprintf(fout,"\t%s = svc%s_create(RPC_ANYSOCK",TRANSP,transp);
  2321. X    if (streq(transp,"tcp")) {
  2322. X        fprintf(fout,", 0, 0");
  2323. X    }
  2324. X    fprintf(fout,");\n");
  2325. X    fprintf(fout,"\tif (%s == NULL) {\n",TRANSP);
  2326. X    fprintf(fout,"\t\tfprintf(stderr,\"cannot create %s service.\\n\");\n",transp);
  2327. X    fprintf(fout,"\t\texit(1);\n");
  2328. X    fprintf(fout,"\t}\n");
  2329. X
  2330. X    for (l = defined; l != NULL; l = l->next) {
  2331. X        def = (definition *) l->val;
  2332. X        if (def->def_kind != DEF_PROGRAM) {    
  2333. X            continue;
  2334. X        }
  2335. X        for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
  2336. X            fprintf(fout,
  2337. X                "\tif (! svc_register(%s, %s, %s, ",
  2338. X                TRANSP,def->def_name,vp->vers_name);
  2339. X            pvname(def->def_name,vp->vers_num);
  2340. X            fprintf(fout,", IPPROTO_%s)) {\n",
  2341. X                streq(transp,"udp") ? "UDP" : "TCP");
  2342. X             fprintf(fout,
  2343. X                "\t\tfprintf(stderr,\"unable to register (%s, %s, %s).\\n\");\n",
  2344. X                def->def_name,vp->vers_name, transp);
  2345. X            fprintf(fout,"\t\texit(1);\n");
  2346. X            fprintf(fout,"\t}\n");
  2347. X        }
  2348. X    }
  2349. X}
  2350. X
  2351. X
  2352. X/*
  2353. X * write the rest of the service
  2354. X */
  2355. Xvoid
  2356. Xwrite_rest()
  2357. X{
  2358. X    fprintf(fout,"\tsvc_run();\n");
  2359. X    fprintf(fout,"\tfprintf(stderr,\"svc_run returned\\n\");\n");
  2360. X    fprintf(fout,"\texit(1);\n");
  2361. X    fprintf(fout,"}\n");
  2362. X}
  2363. X
  2364. X
  2365. X
  2366. Xstatic
  2367. Xwrite_program(def)
  2368. X    definition *def;
  2369. X{
  2370. X    version_list *vp;
  2371. X    proc_list *proc;
  2372. X    int filled;
  2373. X
  2374. X    for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
  2375. X        fprintf(fout,"\n");
  2376. X        fprintf(fout,"static void\n");
  2377. X        pvname(def->def_name, vp->vers_num);
  2378. X        fprintf(fout,"(%s, %s)\n",RQSTP,TRANSP);
  2379. X        fprintf(fout,"    struct svc_req *%s;\n",RQSTP);
  2380. X        fprintf(fout,"    SVCXPRT *%s;\n",TRANSP);
  2381. X        fprintf(fout,"{\n");
  2382. X
  2383. X        filled = 0;    
  2384. X        fprintf(fout,"\tunion {\n");
  2385. X        for (proc = vp->procs; proc != NULL; proc = proc->next) {
  2386. X            if (streq(proc->arg_type,"void")) {
  2387. X                continue;
  2388. X            }
  2389. X            filled = 1;
  2390. X            fprintf(fout,"\t\t");    
  2391. X            if (proc->arg_prefix) {
  2392. X                if (streq(proc->arg_prefix,"enum")) {
  2393. X                    fprintf(fout,"enum ");
  2394. X                } else {
  2395. X                    fprintf(fout,"struct ");
  2396. X                }
  2397. X            }
  2398. X            fprintf(fout,"%s ",proc->arg_type);
  2399. X            pvname(proc->proc_name,vp->vers_num);
  2400. X            fprintf(fout,"_arg;\n");
  2401. X        }
  2402. X        if (! filled) {
  2403. X            fprintf(fout,"\t\tint fill;\n");
  2404. X        }
  2405. X        fprintf(fout,"\t} %s;\n",ARG);
  2406. X        fprintf(fout,"\tchar *%s;\n",RESULT);
  2407. X        fprintf(fout,"\tbool_t (*xdr_%s)(), (*xdr_%s)();\n",ARG,RESULT);
  2408. X        fprintf(fout,"\tchar *(*%s)();\n",ROUTINE);
  2409. X        for (proc = vp->procs; proc != NULL; proc = proc->next) {
  2410. X            fprintf(fout,"\textern ");
  2411. X            if (proc->res_prefix) {
  2412. X                fprintf(fout,"%s ",proc->res_prefix);
  2413. X            }
  2414. X            fprintf(fout,"%s *",proc->res_type);
  2415. X            pvname(proc->proc_name,vp->vers_num);
  2416. X            fprintf(fout,"();\n");
  2417. X        }
  2418. X        fprintf(fout,"\n");
  2419. X        fprintf(fout,"\tswitch (%s->rq_proc) {\n",RQSTP);
  2420. X
  2421. X        fprintf(fout,"\tcase NULLPROC:\n");
  2422. X        fprintf(fout,"\t\tsvc_sendreply(%s, xdr_void, NULL);\n",TRANSP);
  2423. X        fprintf(fout,"\t\treturn;\n\n");
  2424. X
  2425. X        for (proc = vp->procs; proc != NULL; proc = proc->next) {
  2426. X            fprintf(fout,"\tcase %s:\n",proc->proc_name);
  2427. X            fprintf(fout,"\t\txdr_%s = xdr_%s;\n",ARG,proc->arg_type);
  2428. X            fprintf(fout,"\t\txdr_%s = xdr_%s;\n",RESULT,proc->res_type);
  2429. X            fprintf(fout,"\t\t%s = (char *(*)()) ",ROUTINE);
  2430. X            pvname(proc->proc_name,vp->vers_num);
  2431. X            fprintf(fout,";\n");
  2432. X            fprintf(fout,"\t\tbreak;\n\n");
  2433. X        }
  2434. X        fprintf(fout,"\tdefault:\n");
  2435. X        printerr("noproc",TRANSP);
  2436. X        fprintf(fout,"\t\treturn;\n");
  2437. X        fprintf(fout,"\t}\n");
  2438. X
  2439. X        fprintf(fout,"\tbzero(&%s, sizeof(%s));\n",ARG,ARG);
  2440. X        printif("getargs",TRANSP,"&",ARG);
  2441. X        printerr("decode",TRANSP);
  2442. X        fprintf(fout,"\t\treturn;\n");
  2443. X        fprintf(fout,"\t}\n");
  2444. X
  2445. X        fprintf(fout,"\t%s = (*%s)(&%s);\n",RESULT,ROUTINE,ARG);
  2446. X        printif("sendreply",TRANSP,"",RESULT);
  2447. X        printerr("systemerr",TRANSP);
  2448. X        fprintf(fout,"\t}\n");
  2449. X
  2450. X        printif("freeargs",TRANSP,"&",ARG);
  2451. X        fprintf(fout,"\t\tfprintf(stderr,\"unable to free arguments\\n\");\n");
  2452. X        fprintf(fout,"\t\texit(1);\n");
  2453. X        fprintf(fout,"\t}\n");
  2454. X
  2455. X        fprintf(fout,"}\n\n");
  2456. X    }
  2457. X}
  2458. X    
  2459. Xstatic
  2460. Xprinterr(err,transp)
  2461. X    char *err;
  2462. X    char *transp;
  2463. X{
  2464. X    fprintf(fout,"\t\tsvcerr_%s(%s);\n",err,transp);
  2465. X}
  2466. X
  2467. Xstatic
  2468. Xprintif(proc,transp,prefix,arg)
  2469. X    char *proc;
  2470. X    char *transp;
  2471. X    char *prefix;
  2472. X    char *arg;
  2473. X{
  2474. X    fprintf(fout,"\tif (! svc_%s(%s, xdr_%s, %s%s)) {\n",
  2475. X        proc,transp,arg,prefix,arg);
  2476. X}
  2477. X
  2478. Xstatic char *
  2479. Xlocase(str)
  2480. X    char *str;
  2481. X{
  2482. X    char c;
  2483. X    static char buf[100];
  2484. X    char *p = buf;
  2485. X
  2486. X    while (c = *str++) {
  2487. X        *p++ = (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c;
  2488. X    }
  2489. X    *p = 0;
  2490. X    return(buf);
  2491. X}
  2492. X
  2493. X
  2494. Xstatic
  2495. Xpvname(pname,vnum)
  2496. X    char *pname;
  2497. X    char *vnum;
  2498. X{
  2499. X    fprintf(fout,"%s_%s",locase(pname),vnum);
  2500. X}
  2501. X
  2502. SHAR_EOF
  2503. if test 5764 -ne "`wc -c < 'rpc/rpcgen/rpc_svcout.c'`"
  2504. then
  2505.     echo shar: "error transmitting 'rpc/rpcgen/rpc_svcout.c'" '(should have been 5764 characters)'
  2506. fi
  2507. chmod 444 'rpc/rpcgen/rpc_svcout.c'
  2508. fi
  2509. exit 0
  2510. #    End of shell archive
  2511.  
  2512.